package com.bang.study.spring.controller;

import com.bang.study.spring.bean.Person;
import com.bang.study.spring.dao.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName: TestController
 * @author: BANG
 * @Date: 2019/11/13 10:04
 * @Version: 1.0
 * @Modified By:
 * @Desc: TODO
 */
@Controller
public class TestController {


    @Autowired
    private Person person;

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/test")
    @ResponseBody
    public String test() {
        System.err.println(person);
        return "success";
    }


    @GetMapping("/test1")
    @ResponseBody
    public Object test2() {
        List<String> users = userMapper.getUsers();
        System.out.println(users);

        return users.get(0);
    }


    @GetMapping("/test2")
    @ResponseBody
    public Object lists(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "10") int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<String> list1 = userMapper.getUsers();
        System.out.println(list1.size());
        List<String> list2 = userMapper.getUsers();
        System.out.println(list2.size());
        PageInfo<String> pageInfo = new PageInfo<>(list1);
        return pageInfo;
    }


}
